// 快手小游戏适配脚本
// 防止重复加载
if ((globalThis as any).__kuaishouAdapterLoaded) {
  console.log('快手适配脚本已加载，跳过重复加载');
} else {
  (globalThis as any).__kuaishouAdapterLoaded = true;

  // 禁用WASM支持检测
  if (typeof window !== 'undefined') {
    // 覆盖WASM检测
    (window as any).WebAssembly = undefined;
    
    // 强制使用JS版本
    if ((window as any).cc && (window as any).cc.sys) {
      (window as any).cc.macro = (window as any).cc.macro || {};
      (window as any).cc.macro.CLEANUP_IMAGE_CACHE = true;
    }
  }

  // 添加快手小游戏特定的polyfills
  if (typeof (globalThis as any).global === 'undefined') {
    (globalThis as any).global = globalThis || this || window;
  }

  // 确保Math对象完整
  if (!Math.fround) {
    Math.fround = function(x: number): number {
      return new Float32Array([x])[0];
    };
  }

  // 禁用SharedArrayBuffer相关功能
  if (typeof (globalThis as any).SharedArrayBuffer !== 'undefined') {
    (globalThis as any).SharedArrayBuffer = undefined;
  }

  console.log('快手小游戏适配脚本加载完成');
}
